package com.atguigu.lease.common.exception;

import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.common.result.ResultCodeEnum;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Package: com.atguigu.lease.common.exception
 * @ClassName: GlobalExceptionHandlers
 * @Author luu
 * @create 2024/10/4 11:33
 * @Description:
 */
@RestControllerAdvice //@ControllerAdvice + @ResponseBody  全局异常处理
public class GlobalExceptionHandlers {

    @ExceptionHandler(LeaseException.class)//用于声明处理异常的方法，`value`属性用于声明该方法处理的异常类型
    public Result leaseExceptionHandler(LeaseException e){
        e.printStackTrace(); //打印空白输出 ，输出报错信息
        ResultCodeEnum resultCodeEnum = e.getResultCodeEnum();
        return Result.build(null,resultCodeEnum);
    }

    @ExceptionHandler(Exception.class)
    public Result exception(Exception e){
        e.printStackTrace();
        return Result.fail();
    }

}
